﻿// Decompiled with JetBrains decompiler
// Type: MCM.Common.Dropdown`1
// Assembly: MCMv5, Version=5.10.2.0, Culture=neutral, PublicKeyToken=null
// MVID: 7AB326B9-B2B4-41C2-9177-68E944071101
// Assembly location: D:\steam\steamapps\workshop\content\261550\2859238197\bin\Win64_Shipping_Client\MCMv5.dll

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.CompilerServices;

#nullable enable
namespace MCM.Common
{
  public sealed class Dropdown<T> : 
    List<T>,
    IEqualityComparer<Dropdown<T>>,
    INotifyPropertyChanged,
    ICloneable
  {
    private int _selectedIndex;
    private T? _selectedValue;

    public static Dropdown<T> Empty => new Dropdown<T>((IEnumerable<T>) Array.Empty<T>(), 0);

    public event PropertyChangedEventHandler? PropertyChanged;

    public int SelectedIndex
    {
      get => this._selectedIndex;
      set => this.SetField<int>(ref this._selectedIndex, value, nameof (SelectedIndex));
    }

    public T SelectedValue
    {
      get => this[this.SelectedIndex];
      set
      {
        if (!this.SetField<T>(ref this._selectedValue, value, nameof (SelectedValue)))
          return;
        int num = this.IndexOf(value);
        if (num == -1)
          return;
        this.SelectedIndex = num;
      }
    }

    public Dropdown(IEnumerable<T> values, int selectedIndex)
      : base(values)
    {
      this.SelectedIndex = selectedIndex;
      if (this.SelectedIndex == 0 || this.SelectedIndex < this.Count)
        ;
    }

    private void OnPropertyChanged([CallerMemberName] string? propertyName = null)
    {
      PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
      if (propertyChanged == null)
        return;
      propertyChanged((object) this, new PropertyChangedEventArgs(propertyName));
    }

    private bool SetField<TVal>(ref TVal field, TVal value, [CallerMemberName] string? propertyName = null)
    {
      if (EqualityComparer<TVal>.Default.Equals(field, value))
        return false;
      field = value;
      this.OnPropertyChanged(propertyName);
      return true;
    }

    public bool Equals(Dropdown<T>? x, Dropdown<T>? y)
    {
      int? selectedIndex1 = x?.SelectedIndex;
      int? selectedIndex2 = y?.SelectedIndex;
      return selectedIndex1.GetValueOrDefault() == selectedIndex2.GetValueOrDefault() & selectedIndex1.HasValue == selectedIndex2.HasValue;
    }

    public int GetHashCode(Dropdown<T> obj) => obj.SelectedIndex;

    public override int GetHashCode() => this.GetHashCode(this);

    public override bool Equals(object? obj)
    {
      return obj is Dropdown<T> y ? this.Equals(this, y) : this == obj;
    }

    public object Clone() => (object) new Dropdown<T>((IEnumerable<T>) this, this.SelectedIndex);
  }
}
